package poc.gridfs;

import java.io.IOException;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

	/**
	 * <p>Class       : test.encoder.EncoderThread
	 * <p>Descdription: 验证Encoder对CPU的耗费情况
	 * @author  顾力行-gulixing@msn.com
	 * @version 1.0.0
	 */
	public class GridFSThread extends Thread {
		
		private String dbUrl;
		private String fileUris;
		
		public int count;
		
	public GridFSThread(String dbUrl, String fileUris) {
		this.dbUrl = dbUrl;
		this.fileUris = fileUris;
	}
	/**
	 * Logger for this class
	 */
	private static final Logger logger = LoggerFactory.getLogger(GridFSThread.class);
		    
	    @Override
	    public void run() {
	    	GridFSDao fsdao = new GridFSDao(this.dbUrl);
	    	while(true){
	    		if(count % 1000 == 0){
//	    			logger.info("{} saved{} records",this.getName(),count);
	    		}
	    		if(count>0 && count % 100000==0){
	    	        logger.info("{} finished at:{}",this.getName(),new Date());
	    		    break;
	    		}
	    		try {
	    		    for (String file : fileUris.split(",")) {
//	    		        logger.info("file is:{}",file);
	    		        fsdao.save(file);
                    }
                    ++count;
//					logger.info("{}存入了{}个文件",this.getName(),count);
				} catch (IOException e1) {
				    logger.error("文件插入失败",e1);
				}
	    	}
	    }	
}

